import { Md5 } from 'ts-md5'
import { LoginFormInterface } from '@/ts/type'
import moment from 'moment'
import { Message } from '@/plugins/element'

// 开发中的通知
export const noDeal = () => {
  Message.info('功能正在开发中，请耐心等待！！')
}

// 对字符串进行加密
export const md5Pwd = (str: string) => {
  const md5: any = new Md5()
  md5.appendAsciiStr(str)
  return md5.end() // 加密后的md5 密码
}

// md5加密后的密码
export const EncryptPassword = (form_login: LoginFormInterface) => ({
  username: form_login.username,
  password: md5Pwd(form_login.password),
})

// 处理时间格式
export const dealDateTime = (time: string) => moment(time).format('YYYY-MM-DD HH:mm:ss')

// 处理时间格式
export const dealDate = (time: string) => moment(time).format('YYYY-MM-DD')

// 处理时间格式
export const dealTime = (time: string) => moment(time).format('HH:mm:ss')

// 判断字符串或者数组为空
export const isEmpty = (str: string | string[]): boolean => str === '' || str === null || str === undefined || str.length === 0

// 处理新增的默认数据
export const dealText = (val: string): string => {
  const textStr = /^请及时/
  if (textStr.test(val)) {
    return '无'
  }
  return val
}

// 日期时间组件的时间处理
export const shortcuts = [
  {
    text: '昨天',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24)
      return [start, end]
    },
  },
  {
    text: '上周',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
      return [start, end]
    },
  },
  {
    text: '上个月',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setTime(start.getTime() - 3600 * 1000 * 24 * 30)
      return [start, end]
    },
  },

]